package com.bsj.power.job.web.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.bsj.power.common.config.exception.ApiException;
import com.bsj.power.common.config.global.JsonResult;
import com.bsj.power.common.config.global.JsonResultEnum;
import com.bsj.power.common.def.dto.PageDTO;
import com.bsj.power.common.def.entity.exp.Experience;
import com.bsj.power.common.def.dto.job.ExperienceDTO;
import com.bsj.power.job.service.ExperienceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yinhao
 * @version 1.0
 * @description 经验
 * @date 2024/5/28
 */
@RestController
@RequestMapping("/experience")
//@SaCheckPermission("/job/experience")
public class ExperienceController {

    @Autowired
    private ExperienceService experienceService;

    /**
     * 添加修改经验反馈
     * @param dto
     * @return
     */
    @PostMapping("/doAddAndUpdateExp")
    public JsonResult doAddAndUpdateExp(@RequestBody ExperienceDTO dto) throws Exception{
        return experienceService.addAndUpdate(dto);
    }

    /**
     * 获取经验反馈列表
     * @param dto
     * @return
     */
    @GetMapping("/doExpPageList")
    public JsonResult<List<Experience>> doExpPageList(PageDTO dto) {
        return experienceService.pageList(dto);
    }

    /**
     * 根据ID或取详细内容
     * @param experienceId
     * @return
     */
    @GetMapping("/doExpFindIdByInfo")
    public JsonResult<Experience> doExpFindIdByInfo(Long experienceId) {
        if (experienceId == null) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        return experienceService.findIdByInfo(experienceId);
    }

    /**
     * 批量删除
     * @param dto
     * @return
     */
    @PostMapping("/doDeleteByIdExp")
    public JsonResult<Integer> doDeleteByIdExp(@RequestBody ExperienceDTO dto) {
        Long[] experienceIds = dto.getExperienceIds();
        if (experienceIds == null) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        return experienceService.deleteByIds(experienceIds);
    }
}
